package com.kunpeng.weibo;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;

import com.kunpeng.weibo.tencent.TencentWeibo;
import com.kunpeng.weibo.tencent.beans.OAuth;
import com.kunpeng.weibo.utils.ShareManager;
import com.kunpeng.weibo.weixin.Weixin;
import com.lee.share.R;

public class ShareActivity extends Activity {
	EditText	etContent;
	Button		btnOk;
	WebView		webView;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		ShareManager.getInstance().init();

		new Thread() {
			public void run() {
				//				SinaWeibo.getInstance().newAuthorize_API().authorize(webView, new AuthorizeInterface() {
				//
				//					@Override
				//					public void authorizeSuccessful(Oauth2AccessToken accessToken) {
				//						Log.i("lijinzhe", "authorizeSuccessful   token:" + accessToken.getAccessToken());
				//					}
				//
				//					@Override
				//					public void authorizeFailed(String message) {
				//						Log.i("lijinzhe", "authorizeFailed   message:" + message);
				//					}
				//				});
				TencentWeibo.getInstance().newAuthorize_API().authorize(webView, new com.kunpeng.weibo.tencent.utils.AuthorizeInterface() {

					@Override
					public void authorizeSuccessful(OAuth oauth) {
						Log.i("lijinzhe", "authorizeSuccessful   token:" + oauth.getOauth_token() + "   secret:" + oauth.getOauth_token_secret());
					}

					@Override
					public void authorizeFailed(String message) {
						Log.i("lijinzhe", "authorizeFailed   message:" + message);
					}
				});
			};
		}.start();

		webView = (WebView) findViewById(R.id.webview);
		etContent = (EditText) findViewById(R.id.etContent);
		btnOk = (Button) findViewById(R.id.btnOk);
		btnOk.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				new Thread() {
					public void run() {
						//						int result = SinaWeibo.getInstance().newStatuses_API().update(etContent.getText().toString().trim(), 0, 0, "");
						//						Log.i("lijinzhe", "result:" + result);
//						String result = TencentWeibo.getInstance().newT_API().add(etContent.getText().toString().trim(), 0, 0);
//						Log.i("lijinzhe", "result:" + result);
						Weixin.getInstance().init(ShareActivity.this, "wx16b177292454fffc", "37b237f0d6799470faa1af86c0ff539a");
						Weixin.getInstance().getSendText_API().sendText("lijinzhe");
					};
				}.start();
			}
		});
	}
}
